package gb.demo.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import gb.demo.entity.Label;
import gb.demo.entity.User;
import gb.demo.entity.Userdescrip;
import gb.demo.mapper.UserDescripMapper;
import gb.demo.service.UserDescripService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import gb.demo.common.R;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Controller
@MapperScan("gb.demo.mapper")
public class UserDescripController {
    @Autowired
    private UserDescripService userDescripService;
    @Autowired
    private UserDescripMapper userDescripMapper;

    //页面跳转
    @GetMapping("/user/userDescriptionPage")
    public String userDescriptionPage() {
        return "/User/userDescription";
    }

    //    测试
    @RequestMapping("/UserDescripTest")
    @ResponseBody
    public R labelTest() {
        List<Userdescrip> list = userDescripService.list();
        list.stream().forEach(System.out::println);
        return R.success(list);
    }

    //    查看用户画像
    @RequestMapping("/user/profile")
    @ResponseBody
    public R userProfile(HttpSession session) {
        User user = (User) session.getAttribute("loginUser");
        if (user != null) {
            List<Userdescrip> userdescrips = userDescripMapper.findPreferenceByUserId(user.getUserid());
            if (userdescrips == null)
                return R.error("暂无相关信息");
            return R.success(userdescrips);
        }
        return R.error("请登陆后重试");
    }
}
//用户画像就不要管理了 不好看
